<template>
	<div class="bg-act-box">
		<el-dialog
		  :title="title"
		  :visible.sync="dialogVisible"
		  width="30%"
		  :before-close="handleClose">
		  <div class="list-item" v-for="(item,index) in list">
			  <div class="o-u-box">
					<p class="m-s-txt-lb">{{item.gdname}}:</p>
					<el-image
						  style="width: 100px; height: 100px"
						  :src="item.gd_img"></el-image>
					<div class="u-btn" @click.stop="chooseImg(index)">+上传替换</div> 
			  </div>
		  </div>
		</el-dialog>
	</div>
</template>

<script>
	import uploadPic from "@/js/upload/UploadPic.js";
	import staticConst from "@/js/const/StaticConst.js";
	export default
	{
		data()
		{
			return{
				title:"",
				dialogVisible:false,
				list : [],
				pIndex:-1,
				act:""
			}
		},
		
		methods:
		{
			showWin(data)
			{
				this.dialogVisible = true;
				console.log("showWin===:",data);
				this.title = "活动产品图片设置";
				this.act = data.act;
				this.pIndex = data.pIndex;
				this.list = data.list;
			},
			
			handleClose()
			{
				this.dialogVisible = false;
			},
			
			chooseImg(index)
			{
				let that = this;
				uploadPic.idyun = 22;
				uploadPic.activeId = 1;
				uploadPic.type = staticConst.UPLOAD_INTER_ACTIVE;
				uploadPic.uploadSussecc = uploadSuccess;
				uploadPic.chooseImage1(callBack);
				
				function callBack(data)
				{
					that.list[index].gd_img = data.url;  //显示图片
				}
				
				function uploadSuccess(data)
				{
					let obj = {};
					that.list[index].gd_img = data.url;  //显示图片
					obj.act = that.act;
					obj.url = data.url;
					obj.baseUrl = data.name;
					obj.index = index;
					obj.pIndex = that.pIndex;
					obj.goodsId = that.list[index].goods_id;
					console.log("sssssssssssssssssssssssssss")
					that.$emit("editGdsImg",obj);
					that.$forceUpdate();
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	
	.bg-act-box
	{
		::v-deep.el-dialog
		{
			margin-top: 40vh !important;
		}
	}
	
	.m-s-txt-lb
	{
		padding-right: 15px;
		width: 180px;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		overflow: hidden;
	}
	.o-u-box
	{
		display:flex;
		align-items: center;
		padding-top: 20px;
		.u-btn
		{
			margin-left: 10px;
			padding: 4px 20px;
			background-color: #3388FF;
			color:#FFF;
			border-radius: 4px;
			cursor: pointer;
		}
	}
	
</style>